From 8320f2a8745efb7c78c4bfcd7d4fde5d83cbb8ad Mon Sep 17 00:00:00 2001 From: robertlipe Date: Mon, 5 Aug 2013 02:59:01 +0000 Subject: [PATCH] Add new humminbird v3 format. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4506 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/humminbird.cc | 74 +++++--- gpsbabel/reference/humminbird-rte-v2.hwr | Bin 0 -> 532 bytes gpsbabel/reference/humminbird-rte-v2~gpx.gpx | 186 +++++++++++++++++++ gpsbabel/reference/humminbird-rte-v3.hwr | Bin 0 -> 640 bytes gpsbabel/reference/humminbird-rte-v3~gpx.gpx | 186 +++++++++++++++++++ gpsbabel/testo.d/humminbird.test | 10 + 6 files changed, 434 insertions(+), 22 deletions(-) create mode 100644 gpsbabel/reference/humminbird-rte-v2.hwr create mode 100644 gpsbabel/reference/humminbird-rte-v2~gpx.gpx create mode 100644 gpsbabel/reference/humminbird-rte-v3.hwr create mode 100644 gpsbabel/reference/humminbird-rte-v3~gpx.gpx diff --git a/gpsbabel/humminbird.cc b/gpsbabel/humminbird.cc index d654ddade..8fc8c0fb0 100644 --- a/gpsbabel/humminbird.cc +++ b/gpsbabel/humminbird.cc @@ -1,7 +1,7 @@ /* Copyright (C) 2008 Björn Augustsson, oggust@gmail.com Copyright (C) 2008 Olaf Klein, o.b.klein@gpsbabel.org - Copyright (C) 2005 Robert Lipe, robertlipe@usa.net + Copyright (C) 2005-2013 Robert Lipe, robertlipe@gpsbabel.org This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,8 +22,9 @@ #include #include #include +#include + #include "defs.h" -#include "avltree.h" #define MYNAME "humminbird" @@ -31,11 +32,12 @@ #define RTE_NAME_LEN 20 #define TRK_NAME_LEN 20 #define MAX_RTE_POINTS 50 +#define MAX_ITEMS_PER_GROUP 12 /* I suspect that these are actually struct signature { - uint8_t format, // 1 = track, 2 = waypoint, 3 = route + uint8_t format, // 1 = track, 2 = waypoint, 3 = route, 4 = iTrack uint8_t version, gpuint16 record_length } @@ -43,11 +45,12 @@ struct signature { The v3 TRK_MAGIC doesn't have a length, probably because it wouldn't fit. (It would be 0x200008) -Still, they're usful in the code as a plain signature. +Still, they're useful in the code as a plain signature. */ #define TRK_MAGIC 0x01030000L #define TRK_MAGIC2 0x01021F70L #define WPT_MAGIC 0x02020024L +#define WPT_MAGIC2 0x02030024L // New for 2013. No visible diff?! #define RTE_MAGIC 0x03030088L #define EAST_SCALE 20038297.0 /* this is i1924_equ_axis*M_PI */ @@ -135,6 +138,26 @@ typedef struct humminbird_trk_point_old_s { int16_t deltanorth; } humminbird_trk_point_old_t; +typedef struct group_header { + gbuint8 status; + gbuint8 icon; + gbuint16 depth; + gbuint32 time; /* a time_t, in UTC */ + gbuint16 parent_idx; + gbuint16 reserved1; + gbuint16 first_body_index; + gbuint16 reserved2; + char name[WPT_NAME_LEN]; +} group_header_t; + +typedef struct group_body { + gbuint8 status; + gbuint8 icon; + gbuint16 next_idx; + gbuint16 item[MAX_ITEMS_PER_GROUP]; +} group_body_t; + + static const char* humminbird_icons[] = { "Normal", /* 0 */ "House", /* 1 */ @@ -172,9 +195,9 @@ static gbfile* fin; static gbfile* fout; static int waypoint_num; static short_handle wptname_sh, rtename_sh, trkname_sh; -static avltree_t* waypoints; static humminbird_rte_t* humrte; static int rte_num; +static QMap map; static arglist_t humminbird_args[] = { @@ -232,25 +255,21 @@ static void humminbird_rd_init(const char* fname) { fin = gbfopen_be(fname, "rb", MYNAME); - waypoints = avltree_init(0, MYNAME); } static void humminbird_rd_deinit(void) { - avltree_done(waypoints); gbfclose(fin); } static void humminbird_read_wpt(gbfile* fin) { - humminbird_waypt_t w; double guder; int num_icons; waypoint* wpt; - char buff[10]; if (! gbfread(&w, 1, sizeof(w), fin)) { fatal(MYNAME ": Unexpected end of file!\n"); @@ -286,11 +305,26 @@ humminbird_read_wpt(gbfile* fin) wpt->icon_descr = humminbird_icons[w.icon]; } - waypt_add(wpt); + // In newer versions, this is an enum (though it looks like a bitfield) + // that describes a sub-status + switch (w.status) { + case 0: // Waypoint not used. So why do we have one? + break; + case 1: // Waypoint permanent. + case 2: // Waypoint temporary. + case 3: // Waypoint man-overboard. + waypt_add(wpt); + break; + case 16: // Waypoint group header. + case 17: // Waypoint group body. + case 63: // Waypoint group invalid. + default: + break; + } /* register the point over his internal Humminbird "Number" */ - snprintf(buff, sizeof(buff), "%d", w.num); - avltree_insert(waypoints, buff, wpt); + QString buff = QString::number(w.num); + map[buff] = wpt; } static void @@ -311,13 +345,14 @@ humminbird_read_route(gbfile* fin) route_head* rte = NULL; for (i = 0; i < hrte.count; i++) { - waypoint* wpt; + const waypoint* wpt; char buff[10]; hrte.points[i] = be_read16(&hrte.points[i]); /* locate the point over his internal Humminbird "Number" */ snprintf(buff, sizeof(buff), "%d", hrte.points[i]); - if (avltree_find(waypoints, buff, (const void**) &wpt)) { + if ((map.value(buff))) { + wpt = map.value(buff); if (rte == NULL) { rte = route_head_alloc(); route_add_head(rte); @@ -571,6 +606,7 @@ humminbird_read(void) switch (signature) { case WPT_MAGIC: + case WPT_MAGIC2: humminbird_read_wpt(fin); break; case RTE_MAGIC: @@ -624,8 +660,6 @@ humminbird_wr_init(const char* fname) setshort_repeating_whitespace_ok(trkname_sh, 1); setshort_defname(trkname_sh, "Track"); - waypoints = avltree_init(0, MYNAME); - waypoint_num = 0; rte_num = 0; } @@ -633,7 +667,6 @@ humminbird_wr_init(const char* fname) static void humminbird_wr_deinit(void) { - avltree_done(waypoints); mkshort_del_handle(&wptname_sh); mkshort_del_handle(&rtename_sh); mkshort_del_handle(&trkname_sh); @@ -910,12 +943,9 @@ humminbird_write_waypoint_wrapper(const waypoint* wpt) waypoint* tmpwpt; xasprintf(&key, "%s\01%.9f\01%.9f", wpt->shortname, wpt->latitude, wpt->longitude); - - if (! avltree_find(waypoints, key, (const void**)&tmpwpt)) { + if (!(tmpwpt = map[key])) { tmpwpt = (waypoint*)wpt; - - avltree_insert(waypoints, key, wpt); - + map[key] = (waypoint*) wpt; tmpwpt->extra_data = gb_int2ptr(waypoint_num + 1); /* NOT NULL */ humminbird_write_waypoint(wpt); } else { diff --git a/gpsbabel/reference/humminbird-rte-v2.hwr b/gpsbabel/reference/humminbird-rte-v2.hwr new file mode 100644 index 0000000000000000000000000000000000000000..cba970c2ab92d71ff4e78b6693fbb28a2b035478 GIT binary patch literal 532 zcmb`^KT1PE5C-rs`;xr(OzjOqy1ueaNJs)1MQ{+&+`tQncmNwaOKVFTAw`7v zhqNih&I?GY%?x>tdw_hfEbRVRhHsri6_SFiPXG7L^Q;1*gJCzz8hRmdY6Rrw-t+Vb zbW&5ZwIVCy%shDh*aw~7sA+~KGV|#9y$iZX)NF^QXy(cD + + + + + + + 0.000000 + + WP001 + WP001 + WP001 + Normal + + + 0.000000 + + WP002 + WP002 + WP002 + Normal + + + 0.000000 + + WP003 + WP003 + WP003 + Normal + + + 0.000000 + + WP004 + WP004 + WP004 + Normal + + + 0.000000 + + WP005 + WP005 + WP005 + Normal + + + 0.000000 + + WP006 + WP006 + WP006 + Normal + + + 0.000000 + + WP007 + WP007 + WP007 + Normal + + + 0.000000 + + WP008 + WP008 + WP008 + Normal + + + 0.000000 + + WP009 + WP009 + WP009 + Normal + + + 0.000000 + + WP010 + WP010 + WP010 + Normal + + + 0.000000 + + WP011 + WP011 + WP011 + Normal + + + RT001 + + 0.000000 + + WP001 + WP001 + WP001 + Normal + + + 0.000000 + + WP002 + WP002 + WP002 + Normal + + + 0.000000 + + WP003 + WP003 + WP003 + Normal + + + 0.000000 + + WP004 + WP004 + WP004 + Normal + + + 0.000000 + + WP005 + WP005 + WP005 + Normal + + + 0.000000 + + WP006 + WP006 + WP006 + Normal + + + 0.000000 + + WP007 + WP007 + WP007 + Normal + + + 0.000000 + + WP008 + WP008 + WP008 + Normal + + + 0.000000 + + WP009 + WP009 + WP009 + Normal + + + 0.000000 + + WP010 + WP010 + WP010 + Normal + + + 0.000000 + + WP011 + WP011 + WP011 + Normal + + + diff --git a/gpsbabel/reference/humminbird-rte-v3.hwr b/gpsbabel/reference/humminbird-rte-v3.hwr new file mode 100644 index 0000000000000000000000000000000000000000..239381af60e657a38c50f793a8ee8bc89bbdd112 GIT binary patch literal 640 zcmb`^yGlbr5C-7iJ-M7@Q)uBEgml7*mqZ)uVWG;MO;ODi`G*=@=Uq%AG_jgnHj8kZO)<^T zl+^Ud-|xcts+if(l-2afKOe%a^~KDE#;SSa{fzU>12**}G!-=;yq^P}XF^Q4XL|`8 f^ELm9C_*=DY18(gv9$bir>xG0|LxZL`!C5C4X$^X literal 0 HcmV?d00001 diff --git a/gpsbabel/reference/humminbird-rte-v3~gpx.gpx b/gpsbabel/reference/humminbird-rte-v3~gpx.gpx new file mode 100644 index 000000000..65dae38c9 --- /dev/null +++ b/gpsbabel/reference/humminbird-rte-v3~gpx.gpx @@ -0,0 +1,186 @@ + + + + + + + + 0.000000 + + WP001 + WP001 + WP001 + Normal + + + 0.000000 + + WP002 + WP002 + WP002 + Normal + + + 0.000000 + + WP003 + WP003 + WP003 + Normal + + + 0.000000 + + WP004 + WP004 + WP004 + Normal + + + 0.000000 + + WP005 + WP005 + WP005 + Normal + + + 0.000000 + + WP006 + WP006 + WP006 + Normal + + + 0.000000 + + WP007 + WP007 + WP007 + Normal + + + 0.000000 + + WP008 + WP008 + WP008 + Normal + + + 0.000000 + + WP009 + WP009 + WP009 + Normal + + + 0.000000 + + WP010 + WP010 + WP010 + Normal + + + 0.000000 + + WP011 + WP011 + WP011 + Normal + + + RT001 + + 0.000000 + + WP001 + WP001 + WP001 + Normal + + + 0.000000 + + WP002 + WP002 + WP002 + Normal + + + 0.000000 + + WP003 + WP003 + WP003 + Normal + + + 0.000000 + + WP004 + WP004 + WP004 + Normal + + + 0.000000 + + WP005 + WP005 + WP005 + Normal + + + 0.000000 + + WP006 + WP006 + WP006 + Normal + + + 0.000000 + + WP007 + WP007 + WP007 + Normal + + + 0.000000 + + WP008 + WP008 + WP008 + Normal + + + 0.000000 + + WP009 + WP009 + WP009 + Normal + + + 0.000000 + + WP010 + WP010 + WP010 + Normal + + + 0.000000 + + WP011 + WP011 + WP011 + Normal + + + diff --git a/gpsbabel/testo.d/humminbird.test b/gpsbabel/testo.d/humminbird.test index 4f600332e..3604bc6bb 100644 --- a/gpsbabel/testo.d/humminbird.test +++ b/gpsbabel/testo.d/humminbird.test @@ -17,3 +17,13 @@ gpsbabel -i humminbird -f ${REFERENCE}/humminbird.hwr -f ${REFERENCE}/track/humm gpsbabel -i gpx -f ${TMPDIR}/combo.gpx -o humminbird -F ${TMPDIR}/funky.hwr -o humminbird_ht -F ${TMPDIR}/funky.ht bincompare ${REFERENCE}/humminbird.hwr ${TMPDIR}/funky.hwr bincompare ${REFERENCE}/track/humminbird.ht ${TMPDIR}/funky.ht + +# In 2012, Humminbird changed their format in incompatible ways. We call them +# v2 and v3 but we don't really know that they have names. The version number +# internally didn't change. + +gpsbabel -i humminbird -f ${REFERENCE}/humminbird-rte-v2.hwr -o gpx,humminbirdextensions=1 -F ${TMPDIR}/humminbird-rte-v2~gpx.gpx +compare ${REFERENCE}/humminbird-rte-v2~gpx.gpx ${TMPDIR}/humminbird-rte-v2~gpx.gpx + +gpsbabel -i humminbird -f ${REFERENCE}/humminbird-rte-v3.hwr -o gpx,humminbirdextensions=1 -F ${TMPDIR}/humminbird-rte-v3~gpx.gpx +compare ${REFERENCE}/humminbird-rte-v3~gpx.gpx ${TMPDIR}/humminbird-rte-v3~gpx.gpx -- 2.30.2